<template>
  <div>
    <topicback :topic="userInfo.wxNickName"></topicback>
    <div class="wealth">
      <div class="user-pic">
        <img :src="userInfo.wxPic" width="64" height="64">
      </div>
      <p class="user-id">ID:{{userInfo.userId}}</p>
      <p class="belong-wealth">共抓取{{userInfo.sucCount ? userInfo.sucCount : 0}}次，你还有{{userInfo.coin}}喵币</p>
    </div>
    <div class="wealth-detail" v-if="record.length > 0">
      <div class="one-wealth" v-for="(doll, index) of record" :key="index">
        <div class="doll-pic">
          <img :src="doll.wawaImg">
        </div>
        <p class="doll-name">{{doll.wawaName}}</p>
        <p class="scratch-time">{{addTime}}</p>
      </div>
    </div>
    <div class="no-doll" v-else>
      <img src="../assets/picture/have-no-doll.png" width="210" height="210">
    </div>
  </div>
</template>

<script>
  import topicback from '../components/topic-back.vue'

  export default {
    name: 'record',
    components: {
      topicback
    },
    data () {
      return {
        hasHeader: '',
        userInfo: '',
        record: '',
        pageNum: 1,
        peopleId: '',
        scratchTime: ''
      }
    },
    created () {
      document.body.style.backgroundColor = '#ffffff'
    },
    beforeMount () {
      this.hasHeader = this.$utils.getQueryStringByName('token') ? this.$utils.getQueryStringByName('token') : this.$utils.getCookie('WAWA_TOKEN')
    },
    mounted () {
      console.log(this.$utils.hostVaule())
      this.userDetail()
    },
    methods: {
      userDetail () {
        this.$http({
          method: 'get',
          url: 'https://www.likewawa.com/miaozhuapc/v1/user/getUserDetail',
          headers: {'WAWA_TOKEN': this.hasHeader},
          emulateJSON: true
        }).then(function (response) {
          response = JSON.parse(response.bodyText)
          this.userInfo = response.body
          this.peopleId = response.body.userId
          this.$nextTick(() => {
            console.log(this.peopleId)
            this.scratchRecord()
          })
        }, function () {
          console.log(this.hasHeader)
          console.log('稍后重试')
        })
      },
      scratchRecord () {
        this.$http({
          method: 'get',
          url: 'https://www.likewawa.com/miaozhuapc/v1/user/getGameRecord',
          headers: {'WAWA_TOKEN': this.hasHeader},
          body: {pageSize: 10, pageNum: this.pageNum, userId: this.peopleId},
          emulateJSON: true
        }).then(function (response) {
          response = JSON.parse(response.bodyText)
          this.record = response.body
          for (var i = 0; i < response.body.length; i++) {
            console.log(response.body[i].addTime)
            this.scratchTime = this.$utils.parseCastingDate(response.body[i].addTime, 'yyyy-MM-dd')
          }
          console.log(this.scratchTime)
        }, function () {
          console.log('稍后重试')
        })
      }
    }
  }
</script>

<style scope lang="scss">
  html{
    height: 100%;
  }
  .wealth{
    background: #ffdf58;
    .user-pic{
      display: table;
      padding-top: 10px;
      margin: 0 auto;
      img{
        display: inherit;
        border-radius: 50%;
      }
    }
    p{
      font-size: 12px;
      text-align: center;
      color: #1e1e1b;
      &.user-id{
         margin: 9px 0 11px;
      }
      &.belong-wealth{
         padding-bottom: 25px;
      }
    }
  }
  .wealth-detail{
    background: #ffffff;
    overflow: hidden;
    margin: 12px 6px;
    .one-wealth{
      width: calc(50% - 12px);
      float: left;
      margin: 0 6px;
      .doll-pic{
        width: 100%;
        img{
          display: inherit;
          width: 100%;
        }
      }
    }
    .doll-name{
      font-size: 15px;
      color: #1e1e1b;
      font-weight: bold;
      margin: 13px 0 10px;
    }
    .scratch-time{
      font-size: 10px;
      line-height: 10px;
      color: #949494;
      margin-bottom: 20px;
    }
  }
  .no-doll{
    display: table;
    margin: 76px auto 0;
    img{
      display: inherit;
    }
  }
</style>
